<html>
<head><meta charset="utf-8"><title>unreachable-discriminant · t-compiler/const-eval · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/index.html">t-compiler/const-eval</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/unreachable-discriminant.html">unreachable-discriminant</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="135957117"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/unreachable-discriminant/near/135957117" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/unreachable-discriminant.html#135957117">(Oct 17 2018 at 08:18)</a>:</h4>
<p><span class="user-mention" data-user-id="124288">@Oli</span> so about <a href="https://github.com/rust-lang/rust/pull/55142" target="_blank" title="https://github.com/rust-lang/rust/pull/55142">https://github.com/rust-lang/rust/pull/55142</a>...</p>



<a name="135957132"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/unreachable-discriminant/near/135957132" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/unreachable-discriminant.html#135957132">(Oct 17 2018 at 08:19)</a>:</h4>
<p>I can make this into a <code>bug!</code> if you want. Not sure why we'd want an ICE there but well^^</p>



<a name="135957146"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/unreachable-discriminant/near/135957146" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/unreachable-discriminant.html#135957146">(Oct 17 2018 at 08:19)</a>:</h4>
<p>Looking at <a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2015&amp;gist=e75c6dc3f500490e032fff4266bd8682" target="_blank" title="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2015&amp;gist=e75c6dc3f500490e032fff4266bd8682">https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2015&amp;gist=e75c6dc3f500490e032fff4266bd8682</a>, it seems that even before <span class="user-mention" data-user-id="121053">@varkor</span>'s patch, we don't actually get a <code>GetDiscriminant</code> for empty enums</p>



<a name="135957188"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/unreachable-discriminant/near/135957188" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/unreachable-discriminant.html#135957188">(Oct 17 2018 at 08:20)</a>:</h4>
<p>Well. I don't think it's an ICE. It is literally unreachable code.</p>



<a name="135957197"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/unreachable-discriminant/near/135957197" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/unreachable-discriminant.html#135957197">(Oct 17 2018 at 08:20)</a>:</h4>
<p>though I think with the changes around <code>!</code> patterns that <span class="user-mention" data-user-id="116009">@nikomatsakis</span> and I have been planning, that might change</p>



<a name="135957204"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/unreachable-discriminant/near/135957204" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/unreachable-discriminant.html#135957204">(Oct 17 2018 at 08:20)</a>:</h4>
<p>I agree it is likely unreachable currently, but that is an artifact of how we generate MIR</p>



<a name="135957206"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/unreachable-discriminant/near/135957206" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/unreachable-discriminant.html#135957206">(Oct 17 2018 at 08:20)</a>:</h4>
<p>and there is perfectly reasonable MIR that reaches this</p>



<a name="135957215"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/unreachable-discriminant/near/135957215" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/unreachable-discriminant.html#135957215">(Oct 17 2018 at 08:20)</a>:</h4>
<p>just rustc never produces it</p>



<a name="135957216"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/unreachable-discriminant/near/135957216" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/unreachable-discriminant.html#135957216">(Oct 17 2018 at 08:20)</a>:</h4>
<p>You'd still need to be able to create a value of uninhabited type to get here</p>



<a name="135957221"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/unreachable-discriminant/near/135957221" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/unreachable-discriminant.html#135957221">(Oct 17 2018 at 08:20)</a>:</h4>
<p>but I think we should produce it</p>



<a name="135957228"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/unreachable-discriminant/near/135957228" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/unreachable-discriminant.html#135957228">(Oct 17 2018 at 08:21)</a>:</h4>
<p>true, but without validation that's not hard</p>



<a name="135957232"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/unreachable-discriminant/near/135957232" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/unreachable-discriminant.html#135957232">(Oct 17 2018 at 08:21)</a>:</h4>
<p>won't we error out before even getting here?</p>



<a name="135957237"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/unreachable-discriminant/near/135957237" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/unreachable-discriminant.html#135957237">(Oct 17 2018 at 08:21)</a>:</h4>
<p>only through validation</p>



<a name="135957238"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/unreachable-discriminant/near/135957238" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/unreachable-discriminant.html#135957238">(Oct 17 2018 at 08:21)</a>:</h4>
<p>I hope</p>



<a name="135957246"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/unreachable-discriminant/near/135957246" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/unreachable-discriminant.html#135957246">(Oct 17 2018 at 08:21)</a>:</h4>
<p>this is another instance of my pet peeve: enums with 0 variants are not special</p>



<a name="135957251"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/unreachable-discriminant/near/135957251" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/unreachable-discriminant.html#135957251">(Oct 17 2018 at 08:21)</a>:</h4>
<p>just the "is this a valid discriminant" check cannot succeed</p>



<a name="135957289"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/unreachable-discriminant/near/135957289" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/unreachable-discriminant.html#135957289">(Oct 17 2018 at 08:22)</a>:</h4>
<p>but it doesnt have to fail any other way than a bad discriminant for a 5-variant enum does</p>



<a name="135957298"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/unreachable-discriminant/near/135957298" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/unreachable-discriminant.html#135957298">(Oct 17 2018 at 08:22)</a>:</h4>
<p>ok. I remember we used to have some code about erroring out when encountering uninhabited locals</p>



<a name="135957304"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/unreachable-discriminant/near/135957304" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/unreachable-discriminant.html#135957304">(Oct 17 2018 at 08:22)</a>:</h4>
<p>yeah we did, and we killed it, and I am happy about that</p>



<a name="135957308"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/unreachable-discriminant/near/135957308" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/unreachable-discriminant.html#135957308">(Oct 17 2018 at 08:22)</a>:</h4>
<p>at least I couldnt find it any more^^</p>



<a name="135957309"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/unreachable-discriminant/near/135957309" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/unreachable-discriminant.html#135957309">(Oct 17 2018 at 08:22)</a>:</h4>
<p>ok, I agree that fewer special cases are good</p>



<a name="135957314"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/unreachable-discriminant/near/135957314" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/unreachable-discriminant.html#135957314">(Oct 17 2018 at 08:22)</a>:</h4>
<p>I'm just unhappy that we don't have a test case for this path</p>



<a name="135957326"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/unreachable-discriminant/near/135957326" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/unreachable-discriminant.html#135957326">(Oct 17 2018 at 08:23)</a>:</h4>
<p>which we can't have, since rustc just bails out</p>



<a name="135957341"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/unreachable-discriminant/near/135957341" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/unreachable-discriminant.html#135957341">(Oct 17 2018 at 08:23)</a>:</h4>
<p>that's also a good way to put it, yes</p>



<a name="135957390"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/unreachable-discriminant/near/135957390" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/unreachable-discriminant.html#135957390">(Oct 17 2018 at 08:24)</a>:</h4>
<p>yeah, well... that's <a href="https://github.com/solson/miri/issues/196" target="_blank" title="https://github.com/solson/miri/issues/196">https://github.com/solson/miri/issues/196</a></p>



<a name="135957396"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/unreachable-discriminant/near/135957396" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/unreachable-discriminant.html#135957396">(Oct 17 2018 at 08:24)</a>:</h4>
<p>lol the MIR of this code: <a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2015&amp;gist=fad502214672640ae55156215fa77f5c" target="_blank" title="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2015&amp;gist=fad502214672640ae55156215fa77f5c">https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2015&amp;gist=fad502214672640ae55156215fa77f5c</a></p>



<a name="135957402"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/unreachable-discriminant/near/135957402" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/unreachable-discriminant.html#135957402">(Oct 17 2018 at 08:24)</a>:</h4>
<p>brb, getting into the dead spot</p>



<a name="135957427"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/unreachable-discriminant/near/135957427" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/unreachable-discriminant.html#135957427">(Oct 17 2018 at 08:25)</a>:</h4>
<blockquote>
<p>lol the MIR of this code: <a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2015&amp;gist=fad502214672640ae55156215fa77f5c" target="_blank" title="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2015&amp;gist=fad502214672640ae55156215fa77f5c">https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2015&amp;gist=fad502214672640ae55156215fa77f5c</a></p>
</blockquote>
<p>yeah that makes lots of sense actually</p>



<a name="135957429"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/unreachable-discriminant/near/135957429" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/unreachable-discriminant.html#135957429">(Oct 17 2018 at 08:25)</a>:</h4>
<p><code>match x { _ =&gt; ... }</code> is equivalent to <code>let _ = x; ...</code></p>



<a name="135957447"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/unreachable-discriminant/near/135957447" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/unreachable-discriminant.html#135957447">(Oct 17 2018 at 08:26)</a>:</h4>
<p>it is not supposed to inspect the discriminant</p>



<a name="135957473"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/unreachable-discriminant/near/135957473" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/unreachable-discriminant.html#135957473">(Oct 17 2018 at 08:26)</a>:</h4>
<p>so its not even UB, without validity</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>